//
//  KKStudyTopCell.m
//  DoMi
//
//  Created by 康凯 on 2016/12/14.
//  Copyright © 2016年 kk. All rights reserved.
//

#import "KKStudyTopCell.h"
#import "SDCycleScrollView.h"
#import "KKItemListController.h"
#import "KKWebViewVC.h"
#import "KKVideoDetailController.h"

@interface KKStudyTopCell()<SDCycleScrollViewDelegate>
@property(nonatomic,strong)NSMutableArray *bannerImgs;
@property(nonatomic,strong)NSArray *bannerDatas;
@property(nonatomic,weak)SDCycleScrollView *cycleScrollView;
@end

@implementation KKStudyTopCell
-(NSMutableArray *)bannerImgs{
    if(!_bannerImgs){
        _bannerImgs=[NSMutableArray array];
    }
    return _bannerImgs;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, screenWidth-14, 245) delegate:self placeholderImage:[UIImage imageNamed:@""]];
    self.cycleScrollView=cycleScrollView;
    cycleScrollView.autoScroll=NO;
//    cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
    cycleScrollView.currentPageDotColor = [UIColor clearColor]; // 自定义分页控件小圆标颜色
    [self.bannerView addSubview:cycleScrollView];
}

-(void)initBanner:(NSArray *)banners{
    if(banners!=nil&&banners.count>0){
        self.bannerDatas=banners;
        for (KKBannerM *banner in banners) {
            [self.bannerImgs addObject:banner.img];
        }
        self.cycleScrollView.imageURLStringsGroup = self.bannerImgs;
        
    }
    
}

#pragma mark 代理--banner
-(void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    KKBannerM *banner=self.bannerDatas[index];
    if([banner.tid isEqualToString:@"32"]){
        KKWebViewVC *webview=[[KKWebViewVC alloc] init];
        webview.navTitle=banner.title;
        webview.url=banner.url;
        [[KKAppUtils getCurrentVisiableVC:self].navigationController pushViewController:webview animated:YES];
    }else if([banner.tid isEqualToString:@"33"]){//视频
        KKVideoDetailController *detail=[[KKVideoDetailController alloc] init];
        detail.videoId=banner.url;
        [[KKAppUtils getCurrentVisiableVC:self].navigationController pushViewController:detail animated:YES];
    }
    
}

- (IBAction)FreeListClick:(id)sender {
    KKItemListController *itemView=[[KKItemListController alloc] init];
    itemView.barTitle=@"免费试听";
    [[KKAppUtils getCurrentVisiableVC:self].navigationController pushViewController:itemView animated:YES];
}
@end
